package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.LastUserListenPlayVo;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

    @Autowired
    private UserListenProcessService userListenProcessService;


    @GuiGuLogin
    @Operation(summary = "获取用户上次播放声音信息")
    @GetMapping("getLatelyTrack")
    public Result<LastUserListenPlayVo> getLatelyTrack() {
        LastUserListenPlayVo lastUserListenPlayVo = userListenProcessService.getLatelyTrack();
        return Result.ok(lastUserListenPlayVo);
    }


    @GuiGuLogin
    @Operation(summary = "更新播放进度")
    @PostMapping("updateListenProcess")
    public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
        userListenProcessService.updateListenProcess(userListenProcessVo);
        return Result.ok();
    }


    @GuiGuLogin
    @Operation(summary = "获取声音的上次跳出时间")
    @GetMapping("getTrackBreakSecond/{trackId}")
    public Result<BigDecimal> getTrackBreakSecond(@PathVariable("trackId") Long trackId) {
        BigDecimal bigDecimal = userListenProcessService.getTrackBreakSecond(trackId);
        return Result.ok(bigDecimal);
    }
}

